﻿using StrokeCenterSystem.Code.Bll;
using StrokeCenterSystem.Core;
using StrokeCenterSystem.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace StrokeCenterSystem.Areas.StrokeCenter.Controllers
{
    public class InspectionResultController : BaseController
    {
        //
        // GET: /StrokeCenter/InspectionResult/
        /// <summary>
        /// 检验结果页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        public ContentResult Search()
        {
            string triageId = WebUtils.GetString("triageId");
            OperateResult result = InspectionResultManager.getInspectionInfor(triageId);
            DataTable itemDt = new DataTable();
            DataTable mainDt = new DataTable();
            if (result.Result == 1)
            {
                itemDt = JsonHelper.ToDataTable(result.Body.ToString());
                if (itemDt.Rows.Count > 0)
                {
                    mainDt = itemDt.AsEnumerable().Cast<DataRow>().GroupBy(p => p.Field<string>("reportid")).Select(p => p.FirstOrDefault()).OrderByDescending(p => p.Field<string>("sampledate")).CopyToDataTable();
                }
            }
            var resultData = new { mainData = new { Rows = mainDt }, itemData = new { Rows = itemDt } };
            return JsonDate(resultData);
        }
    }
}
